//
//  TableViewCell.m
//  News
//
//  Created by xalo on 16/3/1.
//  Copyright © 2016年 News. All rights reserved.


#import "TableViewCell.h"
#import "PicListModel.h"
#import "UIImageView+WebCache.h"
#import <Reachability.h>
@implementation TableViewCell

-(void)setPicMod:(PicListModel *)picMod {
    
  
    
    _picMod =picMod ;
    
    extern BOOL isWiFiMode;
    Reachability *ablity = [Reachability reachabilityForInternetConnection];
    
    //判断无线,并且判断开关状态
    if (([ablity isReachableViaWiFi])||([ablity isReachable] && !isWiFiMode)||(![ablity  isReachable])) {
        
    [self.image sd_setImageWithURL:[NSURL URLWithString:picMod.list[0][@"kpic"]]placeholderImage:[UIImage imageNamed:@"background"]];
    }
        
       _title.text = picMod.title ;
      _subTitle.text = picMod.intro ;
    
    CGFloat height = [TableViewCell cellOfheightWITString:picMod.intro];
    if (height > 20) {
        CGRect frame = self.subTitle.frame;
        frame.size.height =height;
        self.subTitle.frame =frame;
    }
    
    _picMod.cellHeight = self.image.frame.size.height +self.title.frame.size.height +20 +height;
    
}

+(CGFloat)cellOfheightWITString:(NSString *)string
{
        NSDictionary *dic =[NSDictionary dictionaryWithObject:[UIFont systemFontOfSize:12] forKey:NSFontAttributeName];
    
    CGFloat weith = [UIScreen mainScreen].bounds.size.width ;
    
    CGFloat cellWith = weith - 10;
    CGRect bound = [string boundingRectWithSize:CGSizeMake(cellWith, 2000) options:(NSStringDrawingUsesLineFragmentOrigin)attributes:dic context:nil];
    
    return bound.size.height;
}

-(void)layoutSubviews {
    
    
      
    
}





@end
